#define _CRT_SECURE_NO_WARNINGS 1


#include<queue>
#include<iostream>
#include<cstdlib>
using namespace std;

typedef struct Treenode
{
    struct Treenode* left;
    struct Treenode* right;
    char val;
}TreeNode;

TreeNode* greatnode(char* s, int* const pi)
{
    if (s[*pi] == '#')
    {
        (*pi)++;
        return NULL;
    }

    TreeNode* root = (TreeNode*)malloc(sizeof(TreeNode));
    root->val = s[(*pi)++];
    root->left = greatnode(s, pi);
    root->right = greatnode(s, pi);
    return root;
}

void TreeLeveNode(TreeNode* root,queue<TreeNode*>& q)
{
    if (root == NULL)
    {
        return;
    }
    q.push(root);
    while(!q.empty())
    {
        if (q.front())
        {
            cout << (q.front())->val << ' ';
            q.push(q.front()->left);
            q.push(q.front()->right);
        }
        else
        {
            cout << "0" << ' ';
        }
        q.pop();
    }


}

int main() {
    char s[100] = {"ABCDE#####FG###"};
    int i = 0;
    queue<TreeNode*> q1;
    TreeNode* head = greatnode(s, &i);
    TreeLeveNode(head, q1);
    return 0;
}